package vsqlbuilder.logic.sql;

import java.util.ArrayList;
import java.util.List;

import vsqlbuilder.Utils.typeofConnector;
import vsqlbuilder.Utils.typeofRestriction;

public class QueryRestrictionsList {
	private List<QueryRestriction> allIncludedRestrictions;


	public QueryRestrictionsList() {
		allIncludedRestrictions = new ArrayList<QueryRestriction>();
	}

	public QueryRestriction getResctrictionAt(int index) {
		QueryRestriction qr=this.allIncludedRestrictions.get(index);
		return qr;
	}

	public int getGroupRestriction(int index){
		return this.allIncludedRestrictions.get(index).getGroup();
	}
	
	public String getRestrictionExpression(int index){
		return this.allIncludedRestrictions.get(index).getExpression();
	}
	
	public typeofRestriction getTypeRestriction(int index){
		return this.allIncludedRestrictions.get(index).getTypeRestriction();
	}
	
	public typeofConnector getTypeConnector(int index){
		return this.allIncludedRestrictions.get(index).getTypeConnector();
	}
	
	public String getValue1(int index){
		return this.allIncludedRestrictions.get(index).getValue1();
	}
	
	public String getValue2(int index){
		return this.allIncludedRestrictions.get(index).getValue2();
	}
	
	//Add to a specified position the restriction
	public QueryRestriction addRestriction(int index){
		QueryRestriction qr= new QueryRestriction();
		this.allIncludedRestrictions.add(index, qr);
		return qr;
	}
	
	//Add to the end of the list
	public QueryRestriction addRestriction(){
		QueryRestriction qr= new QueryRestriction();
		this.allIncludedRestrictions.add(qr);
		return qr;
	}
			
	public void removeRestriction(QueryRestriction qr) {
		this.allIncludedRestrictions.remove(qr);
	}

	public List<QueryRestriction> getList() {
		return allIncludedRestrictions;
	}
	
	public void setGroupRestriction(QueryRestriction qr, int group){
		this.allIncludedRestrictions.get(this.allIncludedRestrictions.indexOf(qr)).setGroup(group);
	}
	
	public void setRestrictionExpression(QueryRestriction qr, String expression){
		this.allIncludedRestrictions.get(this.allIncludedRestrictions.indexOf(qr)).setExpresion(expression);
	}
	
	public void setTypeRestriction(QueryRestriction qr, typeofRestriction tr){
		this.allIncludedRestrictions.get(this.allIncludedRestrictions.indexOf(qr)).setTypeRestriction(tr);
	}
	
	public void setTypeConnector(QueryRestriction qr, typeofConnector tc){
		this.allIncludedRestrictions.get(this.allIncludedRestrictions.indexOf(qr)).setTypeConnector(tc);
	}
	
	public void setValue1(QueryRestriction qr, String s){
		this.allIncludedRestrictions.get(this.allIncludedRestrictions.indexOf(qr)).setValue1(s);
	}
	
	public void setValue2(QueryRestriction qr, String s){
		this.allIncludedRestrictions.get(this.allIncludedRestrictions.indexOf(qr)).setValue2(s);
	}
	
}
